package com.mall.goods.application.service;

import com.mall.goods.common.dto.DtGrid;
import com.mall.goods.common.enums.Resp;
import com.mall.goods.common.exception.BusinessException;
import com.mall.goods.common.exception.DtGridException;
import com.mall.user.domain.model.GoodsCommon;
import com.mall.user.domain.port.in.GoodsUserCase;
import com.mall.user.domain.port.out.GoodsUserPort;
import io.micrometer.common.util.StringUtils;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 *  商品服务
 */
@Slf4j
@Service
public class GoodsService implements GoodsUserCase {

    @Resource
    private GoodsUserPort goodsUserPort;

    /**
     * 商品列表JSON数据
     *
     *  @author zqk
     *  @date 2025/11/6
     *  @param dtGridPager 分页参数
     *  @return DtGrid 分页数据
     */
    @Override
    public DtGrid listJson(String dtGridPager) throws DtGridException {
        if (StringUtils.isBlank(dtGridPager)) {
            throw new DtGridException("参数不能为空");
        }
        return goodsUserPort.getGoodsDtGridListForAdminByMyBatis(dtGridPager);
    }

    /**
     *
     * 商品禁售
     * @author yangfei
     * @param commonId
     * @param stateRemark
     */
    @Override
    public void banJson(int commonId, String stateRemark) {
        if(StringUtils.isEmpty(stateRemark)) {
            throw new BusinessException(Resp.STATEREMARK_NOT_EXIST);
        }

        goodsUserPort.banJson(commonId, stateRemark);

    }


    /**
     * 商品通过审核
     * @return
     * @author yangfei
     */
    @Override
    public void passJson(int commonId) {
        if(commonId<=0){
            throw new BusinessException(Resp.INVALID_PARAM);
        }
        goodsUserPort.passJson(commonId);
    }
}